
#include "aconnect/types.hpp"
#include "aconnect/thread_pool.hpp"
#include "aconnect/util.hpp"

boost::detail::atomic_count COUNTER (0l);

void threadProc (int n)
{
	using namespace aconnect;
	util::sleep (rand() * 200/  RAND_MAX );
	std::cout << string ("threadProc: " + boost::lexical_cast<string> (n) + "\n" );

	++COUNTER;
}

int main (int argc, char* args[]) 
{
	using namespace aconnect;

	ThreadPool<int> pool(threadProc, 10);
	
	const int Count = 30;
	for (int n=0; n < Count; ++n) {
		aconnect::util::sleep (20);
		
		pool.process(n);
	}
	
	aconnect::util::sleep (1000);
	pool.wait();

	if (COUNTER == Count)
		std::cout << "All work done" << std::endl;
	else
		std::cout << "Error occured, there are unprocessed items (((." << std::endl;
}
